import TableData from "@/components/public/el-table-pagination"; //主页面列表
import TableLyout from '@/components/commonPublic/tableLyoutDetail.vue'
import CustomDialog from "@/components/stationProductionPage/GroutManage/Grout_task_list/index.vue";
import {
    getTensioningTaskList, //列表页接口
    submitTensioningTask, //提交
    deleteTensioningTask, //删除

} from "@/api/request.js";
import publicForm from "@/components/materialDataManage/fromCom.vue"; //弹框form
import elBreadcrumb from "@/components/public/el-breadcrumb.vue";
import formJs from "./regexDetail.js"; //新增弹框配置
export default {
    name: "Grout_task_listText",
    data() {
        return {
            name: "Grout_task_listText",
            sgisShow: false,
            isLock: false,
            projectId: null,
            projectName: null,
            loading: false,
            btnObj: [], //按钮
            queryCriteriaData: {}, //分页
            searchObj: formJs.searchObj, //搜索条件
            table_config: formJs.table_config, //列表
            radio: "待办",
            // 列表
            getList: {
                userId: "",
                fCompanyid: "", // 施工标段id，不为空
                startDates: "", // 开始时间
                endDates: "", // 截至时间
                machineId: "", // 张拉机id
                fProjectposition: "", //工程部位模糊查询
                taskNo: "", //任务单模糊查询
                fStatus: "", //状态
                keyType: "1", //张拉 1 压浆 2 必填
                modelType: "0",
                fNote: "0", //新加参数 瑞仓1   其他0
            },
            isShow: false, //是否显示弹框
            statusNum: null, //点击那个按钮
            dataFid: null, //列表详情id
            currentRow: null, //列表详情
            activeIndex: "1",
            fId: null, //当前数据fId
            tableData: [],
            companyId: null,
            currentRowId: "",
            dialogTitle: null,
        };
    },
    components: {
        TableLyout,
        publicForm,
        TableData,
        
        elBreadcrumb,
        CustomDialog,


    },
    mounted() {
        this.userInfo = JSON.parse(sessionStorage.getItem("yjSmart-userInfo"));
        // this.getList.fCompanyid = this.userInfo.companyId
        this.getList.companyId = this.userInfo.companyId

        this.yj_searchForm(this.getList);
        this.btnRole(this.name)
    },
    methods: {
        refreshList() { //刷新列表
            this.$nextTick(() => {
                this.yj_searchForm(this.getList);
            })
        },
        // 重置按钮
        modelType(e) {
            this.currentRow = "";
            this.dataFid = "";
            if (e == "待办") {
                this.getList.modelType = "0";
            } else {
                this.getList.modelType = "1";
            }
            this.yj_searchForm(this.getList);
        },
        closeDialog() {
            this.isShow = false;
        },
        sgcloseDialog() {
            this.sgisShow = false;
        },


        handleRow() {},
        btnRole(name) {
            if (this.userInfo.userId != 'System') {
                var btnList = [];
                var ModuleList = JSON.parse(sessionStorage.getItem("yjSmart-ModuleList"));
                if (ModuleList.length > 0) {
                    ModuleList.map((item) => {
                        if (item.fEncode == name) {
                            btnList = item.modulebuttonList;
                        }
                    });
                    btnList.map(item => {
                        item['disabled'] = false
                    })
                    this.btnObj = btnList
                }
            } else {
                this.btnObj = formJs.btnObj
            }
        },
        getBtnName(name, status) {
            this.statusNum = status
            this.yj_edit(status)
        },

        // 新增/编辑
        yj_edit(num) {
            if (this.userInfo.userId != 'System') {
                this.statusNum = num

                if (num == 1) { // 编辑
                    this.editText();
                }else if (num == 2) { // 编辑
                   
                    if (this.dataFid != null) {


                        this.editText();
                    } else {
                        this.$message.warning("请先选择需要编辑的数据");

                    }
                } else if (num == 3) { //提交
                    if (this.dataFid != null) {


                        this.yj_submit(0)
                    } else {
                        this.$message.warning("请先选择需要提交的数据");

                    }
                } else if (num == 4) { //删除

                    if (this.dataFid != null) {

                        this.yj_delete(0)

                    } else {
                        this.$message.warning("请先选择需要删除的数据");

                    }
                } else if (num == 7) { //查看

                    if (this.dataFid != null) {
                        this.statusNum = 7
                        this.isShow = true;
                        this.editText();
                    } else {
                        this.$message.warning("请先选择需要查看的数据");

                    }
                }
            } else {
                this.$message.warning("该用户无权限");
            }
        },
        editText() {
            this.isShow = true;
        },
        // 查看
        // 点击查看
        yj_viewForm(row, label) {
            if (label == "任务单号") {
                this.statusNum = 7;
                this.isShow = true;
                this.currentRow = row;
            } 


        },
        // 点击当前行变色
        rowChange(val) {
            this.currentRow = val
            this.dataFid = val.fId;
        },
        // 获取列表数据
        yj_searchForm(data) {
            var obj = {
                userId: this.userInfo.userId, // 查询待办或已办时传 列表页查询不传
                fCompanyid: this.userInfo.companyId, // 施工标段id，不为空
                startDates: "", // 开始时间
                endDates: "", // 截至时间
                machineId: data.machineId, // 查询条件拌合机ID
                fProjectposition: data.fProjectposition, //工程部位模糊查询
                taskNo: data.taskNo, //任务单模糊查询
                fStatus: data.fStatus, //状态
                keyType: "2", //张拉 1 压浆 2 必填
                fNote: "0", //新加参数 瑞仓1   其他0
                modelType: data.modelType, // 0代办 1已办 不传或传空 表示列表页查询
            }
            this.loading = true;
            var that = this;
            getTensioningTaskList(obj)
                .then((res) => {
                    if (res.errcode == 0) {
                        that.loading = false;
                        that.tableData = res.data.pageInfo.list;
                        this.queryCriteriaData = res.data.pageInfo;
                    } else {
                        this.$message.error("列表数据获取失败", res.msg);
                        this.loading = false;
                    }
                })
                .catch((error) => {
                    this.$message.error("列表数据 接口出错", error.msg);
                    this.loading = false;
                });
        },
        // 删除
        yj_delete() {
            if (this.dataFid != "" && this.dataFid != null) {
                this.$confirm("您是否要永久删除此数据?", "提示", {
                        confirmButtonText: "确定",
                        cancelButtonText: "取消",
                        type: "warning",
                    })
                    .then(() => {
                        this.loading = true;
                        this.isLock = true
                        deleteTensioningTask({
                                fId: this.dataFid,
                                fCompanyid:this.currentRow.fCompanyid
                                // userId: this.userInfo.userId, //当前登陆用户ID
                                // userName: this.userInfo.realName, //当前登陆用户名称
                            })
                            .then((res) => {
                                if (res.errcode == 0) {
                                    this.isLock = false
                                    this.loading = false;
                                    this.yj_searchForm(this.getList);
                                    this.$message.success("删除成功");
                                    this.dataFid = null

                                } else {
                                    this.isLock = false
                                    this.$message.error("删除失败", res.msg);
                                    this.loading = false;
                                }
                            })
                            .catch(() => {
                                console.log("删除失败");
                                this.loading = false;
                            });
                    })
                    .catch(() => {
                        this.$message("取消删除");
                    });
            } else {
                return this.$message.error("请先选择需要删除的数据");
            }
        },
        // 提交
        yj_submit() {
            if (this.currentRow != null) {
                if (this.dataFid != "" && this.dataFid != null) {
                    this.$confirm("是否继续提交?", "提示", {
                            confirmButtonText: "确定",
                            cancelButtonText: "取消",
                            type: "warning",
                        })
                        .then(() => {
                            this.isLock = true
                            this.loading = true;
                            submitTensioningTask({
                                    fId: this.dataFid,
                                    fCompanyid: this.currentRow.fCompanyid,
                                    userId: this.userInfo.userId, //当前登录人id
                                    userName: this.userInfo.realName //当前登录人姓名
                                })
                                .then((res) => {
                                    if (res.errcode == 0) {
                                        this.loading = false;
                                        this.dataFid = null
                                        this.isLock = false
                                        this.yj_searchForm(this.getList);
                                        this.$message.success("提交成功");
                                    } else {
                                        this.isLock = false
                                        this.$message.error("提交失败", res.msg);
                                        this.loading = false;
                                        return false;
                                    }
                                })
                                .catch(() => {
                                    this.loading = false;
                                    console.log("提交失败");
                                });
                        })
                        .catch(() => {
                            this.$message("取消提交");
                        });
                } else {
                    return this.$message.error("请先选择需要提交的数据");
                }
            }
        },

    },
};